// 最长的连续序列  [100,4,200,1,3,2] =》[1,2,3,4]  输出 4

/**
 * @param {number[]} nums
 * @return {number}
 */
var longestConsecutive = function (nums) {
  const len = nums.length
  if (!len) return 0
  let result = 1
  let set = new Set(nums)
  console.log(set);

  for (let i = 0; i < len; i++) {
    if (!set.has(nums[i] - 1)) {
      let max = 1
      let cur = nums[i]
      while (set.has(cur + 1)) {
        cur += 1
        max++
      }
      result = Math.max(result, max)
    }
  }

  return result
};


console.log(longestConsecutive([100, 4, 200, 1, 3, 2]));
